
#include<stdio.h>
#define INF 1000000000
#define MAXSIZE 10000
#define MAX 10000

int a[MAX]={0};
int main()
{
 int p,q,k;
 int i;
 while(scanf("%d%d%d%d%d",&a[0],&a[1],&p,&q,&k)!=EOF)
 { 
	 if(k==0) printf("%d",a[0]%MAXSIZE);
	 else if(k==1) printf("%d",a[1]%MAXSIZE);
	 else {for(i=2;i<=k;i++)
	 {
		 a[i]=p*a[i-1]+q*a[i-2];
		 if(a[i]>MAXSIZE)
			 a[i]=a[i]%MAXSIZE;
	 }
	 printf("%d\n",a[k]%MAXSIZE);}
 }
 return 0;
}
//rumtime error
